package com.example.check_oa.controller;

import com.example.check_oa.model.service.AttendanceService;
import com.example.check_oa.model.service.impl.AttendanceServiceImpl;
import com.example.check_oa.utils.GetAntten;
import com.example.comment_oa.aspact.Permission;
import com.example.comment_oa.pojos.SysEmployee;
import com.example.comment_oa.pojos.SysUser;
import com.example.comment_oa.pojos_vo.attendanceVo.IconVo;
import com.example.comment_oa.pojos_vo.attendanceVo.OriginalVo;
import com.example.comment_oa.response.AjaxResponse;
import com.example.comment_oa.response.CustomError;
import com.example.comment_oa.response.CustomErrorType;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@RestController
@RequestMapping("checkOa/attendance")
@CrossOrigin
public class AttendanceController {

    @Resource
    AttendanceService attendanceService;

    //原始考勤记录--签到记录，根据当前月and工号
    @PostMapping("/query")
    AjaxResponse query(@RequestBody OriginalVo originalVo){
        List query = attendanceService.query(originalVo);
        return AjaxResponse.success(query);
    }


    //打卡
    @PostMapping("/add/{day}/{type}")
    AjaxResponse add(@PathVariable("day")String day,@PathVariable("type")int type){
        int add = attendanceService.add(day, type);
        return AjaxResponse.success(add);
    }

    //查看今天有无打卡
    @RequiresPermissions("attendance1")
    @PostMapping("/select1/{day}")
    public AjaxResponse select1(@PathVariable("day")String day){
        return AjaxResponse.success(attendanceService.select1(day));
    }

    //图标
    @PostMapping("icon/{day}/{userNo}/{type}")
    AjaxResponse selcetIcon(@PathVariable("day")String day,@PathVariable("userNo")String userNo,@PathVariable("type")int type){
        List<IconVo> iconVoList = attendanceService.iconList(day, userNo,type);
        return AjaxResponse.success(iconVoList);
    }

    //每月统计报表
//    @Permission("attendance")
    @PostMapping("moth/{userNo}/{time}/{is}/{typeName}")
    AjaxResponse moth(@PathVariable("typeName")String typeName,@PathVariable("userNo")String userNo,@PathVariable("time")String time,@PathVariable("is")int is){
        return AjaxResponse.success(attendanceService.mothAtten(typeName,userNo,time,is));
    }

    //每日统计
    @PostMapping("oneDate/{deptId}/{data}")
    AjaxResponse ontDate(@PathVariable("deptId")int deptId,@PathVariable("data")String data){
        return AjaxResponse.success(attendanceService.oneDate(deptId, data));
    }

    //个人考勤（人员）
    @PostMapping("person/{roles}/{deptId}/{up}")
    AjaxResponse person(@PathVariable("deptId")int deptId,@PathVariable("roles")int roles,@PathVariable("up")int up){
        return AjaxResponse.success(attendanceService.person());
    }

}
